<div id="mainContent" class="omega grid_13">
	<!-- password strength script -->
	<script src="<?php echo base_url();?>admin_style/script/jquery.password_strength.js" type="text/javascript"></script>

    <?php
    isset($user_data) ? $form_title = 'Felhasználó szerkesztése' : $form_title = 'Új felhasználó';
    ?>
    <h1><?php echo $form_title ?></h1>

    <?php
    // ha nincs beolvasva adatbázisból, vagy már szerkesztettük
    if (!isset($user_data->user_login) || $user_data->user_login != set_value('user_login') && set_value('user_login') != '') {
        $user_data->user_login = set_value('user_login');
    }
    if (!isset($user_data->display_name) || $user_data->display_name != set_value('display_name') && set_value('display_name') != '') {
        $user_data->display_name = set_value('display_name');
    }
    if (!isset($user_data->user_email) || $user_data->user_email != set_value('user_email') && set_value('user_email') != '') {
        $user_data->user_email = set_value('user_email');
    }
    ?>

    <div id="form-error" class="error" style="display: none;"></div>
    <div id="form-success" class="success" style="display: none;"></div>
    <div id="form-notice" class="notice" style="display: none;"></div>
    <div id="form-info" class="info" style="display: none;"></div>

    <?php
    if (!isset($user_data->user_id)) {
        echo form_open("admin/users/add_user");
        // ha új user, nem lesz user_id így csinálunk egyet, mert kell a scripthez
        $user_data->user_id = "''";
    } else {
        echo form_open("admin/users/update_user/$user_data->user_id");
    }
    ?>


    <fieldset>
        <legend>
            A csillaggal jelölt adatok megadása kötelező!
        </legend>


        <label class="must lf">
            <span class="inputLabel">Felhasználónév</span>
            <span class="inlineIcon16">
                <img src="<?php echo base_url(); ?>admin_style/assets/loadanim.gif" width="16" height="16" alt="load" style="display:none;" />
            </span>
            <span class="inputWrap"><input class="" type="text" name="user_login" value="<?php echo $user_data->user_login ?>" AUTOCOMPLETE="off" />
            </span>
            <span class="validate_error"><?php echo form_error('user_login'); ?></span> 
        </label>

        <label class="lf must">
            <span class="inputLabel">Becenév</span>
            <span class="inlineIcon16"><img src="<?php echo base_url(); ?>admin_style/assets/loadanim.gif" width="16" height="16" alt="load" style="display:none;" />
            </span>
            <span class="inputWrap"><input class="" type="text" name="display_name" value="<?php echo $user_data->display_name ?>" AUTOCOMPLETE="off" /></span>
            <span class="validate_error"><?php echo form_error('display_name'); ?></span> 
        </label>

        <label class="lf must">
            <span class="inputLabel">E-mail</span>
            <span class="inlineIcon16"><img src="<?php echo base_url(); ?>admin_style/assets/loadanim.gif" width="16" height="16" alt="load" style="display:none;" />
            </span>
            <span class="inputWrap"><input type="text" name="user_email" value="<?php echo $user_data->user_email ?>" AUTOCOMPLETE="off" /></span>
            <span class="validate_error"><?php echo form_error('user_email'); ?></span> 
        </label>

        <label class="lf must userPassword"> 
            <span class="inputLabel">Jelszó</span>
            <input class="fwf strCheck sf"  type="password" name="user_pass" value="" AUTOCOMPLETE="off" />
            <span class="validate_error"><?php echo form_error('user_pass'); ?></span> 
        </label>

        <label class="lf must userPassword">
            <span class="inputLabel">Jelszó mégegyszer</span>
            <span class="inlineIcon16"><img src="<?php echo base_url(); ?>admin_style/assets/loadanim.gif" width="16" height="16" alt="load" style="display:none;" />
            </span>
            <span class="inputWrap"><input type="password" type="text" name="user_pass_1" value="" AUTOCOMPLETE="off" /></span>
            <span class="validate_error"><?php echo form_error('user_pass_1'); ?></span> 
        </label>
    </fieldset>
    <input id="submit_button" class="button ui-button ui-widget ui-state-default ui-corner-all" type="submit" value="Mentés" />
</form>
<script type="text/javascript" charset="utf-8">
    $(document).ready(function() {

    	// PW field
    	$('input.strCheck').password_strength();
        
        $('#mainContent input').keyup(function(){
            // gépelünk input mezőbe akkor ellenőrizük a dolgokat
            var current_input_field = $(this);
            switch(current_input_field.attr('name')){
                case 'user_login':
                case 'user_email':
                    $.ajax({
                        url: '<?php echo site_url('admin/users/ajax_exist_in_database'); ?>',
                        data: {
                            row_name : $(this).attr('name'),
                            record_name : $(this).val(),
                            reg_id : <?php echo $user_data->user_id; ?>
                        },
                        dataType: 'text',
                        type: 'post',
                        success: function (data) {
                            $('#form-error').hide(500);
                            if(data == 'reserved'){
                                // foglalt a dolog.
                                current_input_field.addClass('bad');
                                current_input_field.parent().next().html('Ez már foglalt, kérlek válassz másikat.');
                                $('#submit_button').attr("disabled", "disabled");
                            }else{
                                // leszedjük az attributumokat minden ok
                                current_input_field.parent().next().html("");
                                current_input_field.removeClass('bad');
                                $('#submit_button').removeAttr("disabled");
                            }
                        },
                        error: function(XMLHttpRequest, textStatus, errorThrown){
                            $('#form-success').hide(500);
                            $('#form-error').html("Hiba: " + errorThrown.toString()).show(500);
                        }
                    });
                    break;
                }
            });
        });
</script>

</div>
</div>